/**
 * SEVAS - Swiss Electronic Vaccination Advisor Service / Agile Development
 *
 * $Id: Initializer.java 34 2010-08-19 20:15:52Z zimmr7@bfh.ch $
 */
package ch.bfh.sevas;

import java.util.Date;
import java.util.List;

public class Initializer {

    public static Long initSEVAS() throws Exception {

        Controller controller = new Controller();

        Long id = 0L;

        try {
            List<Patient> patients= controller.findAllPatients();
            for (Patient patient : patients) {
                id = patient.getId();
            }

            if (id.longValue() == 0) {

                Patient patient = new Patient("Zimmermann", "Lea", new DateConverter().convertReverse("20.05.2000"), 0, "756.9217.0769.85");
                patient.addVaccination(new Vaccination("Masern", "Poloral", "Berna", "1-23456-78", "Schluckimpfung", new Date(), "Dr. Matthias Bender"));
                patient.addVaccination(new Vaccination("", "", "", "", "", null, ""));
                patient.addVaccination(new Vaccination("", "", "", "", "", null, ""));
                patient.addVaccination(new Vaccination("", "", "", "", "", null, ""));
                patient.addVaccination(new Vaccination("", "", "", "", "", null, ""));
                patient.addVaccination(new Vaccination("", "", "", "", "", null, ""));
                patient.addVaccination(new Vaccination("", "", "", "", "", null, ""));
                patient.addVaccination(new Vaccination("", "", "", "", "", null, ""));
                controller.create(patient);
                id = patient.getId();
            }

            return id;

        } finally {
            controller.cleanup();
        }
    }
}
